<link href="${rc.getContextPath()}/manage/js/businessJs/my_webuploader.css" rel="stylesheet" type="text/css" />
<style type="text/css">
span.error {
    left: 148px;
    top : 2px
}
</style>
<script type="text/javascript">

    var $currentDialog = $.pdialog.getCurrent();
    
    var $jTabHeader = $("> .tabsHeader", $("div.tabs", $currentDialog));
    
    var $jtabs = $(">.tabsHeaderContent>ul li", $jTabHeader);
    
    var $jgroups = $("> .tabsContent > *", $("div.tabs", $currentDialog));
    
    var componentCount = 0;
    <#if processOperation?? && processOperation.component?size gt 0>
        componentCount = ${processOperation.component?size};        
    </#if>
    
    var capacityCount = 0;
    <#if processOperation?? && processOperation.capacity?size gt 0>
    	capacityCount = ${processOperation.capacity?size};        
    </#if>
    
    var processAttachmentCount = 0;
    <#if processOperation?? && processOperation.attachment?size gt 0>
        processAttachmentCount = ${processOperation.attachment?size};        
    </#if>
    var inspectPictureCount = 0;
    <#if processOperation?? && processOperation.picture?size gt 0>
        processAttachmentCount = ${processOperation.picture?size};        
    </#if>
    var processFile = [];
    
    function popDialogAjaxDone(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            processOperationJs._modifyProcessOperations(json.data);
        }
        $.pdialog.close($currentDialog);
    }
    
    function _addProcessAttachment(data) {
        if(!data)
            return;
        processAttachmentCount ++ ;
        var gridTheadTh = $("#processAttachMentTable", $currentDialog).find("table thead th");
        var _id = "processAttachment_"+processAttachmentCount;
        var tr = "<tr id="+_id+">";
        tr += "<td style='width:"+$(gridTheadTh[0]).width()+"px'><div>"+data.fileName+"</div><input type='hidden' name='attachment["+processAttachmentCount+"].fileName' value='"+data.fileName+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[1]).width()+"px'><div>"+Math.round(data.fileSize/1024)+"kb</div><input type='hidden' name='attachment["+processAttachmentCount+"].attachmentCode' value='"+data.attachmentCode+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[2]).width()+"px'><div><input type='text' class='textInput required' maxlength='20' name='attachment["+processAttachmentCount+"].version'/></div></td>";
        tr += "<td style='width:"+$(gridTheadTh[3]).width()+"px'><a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='_delProcessAttachment(\""+_id+"\");'><@label key='delete.B'>删除</@label></a>";
        tr += "<a title='<@label key='download.B'>下载</@label>' target='dwzExport' class='btnAttach' href='${rc.getContextPath()}/manage/common/downloadAttachement?attachmentCode="+data.attachmentCode+"&fileName="+data.fileName+"'></a></td>"
        tr += "</tr>";
        $("#processAttachMentTable .gridTbody", $currentDialog).find("table tbody").append(tr);
    }
    
    function _addProcessCapacity(data) {
        if(!data)
            return;
        var gridTheadTh = $("#processCapacityTable", $currentDialog).find("table thead th");
        var tr = "<tr id="+data["workUnitCode"]+">";
        tr += "<td style='width:"+$(gridTheadTh[0]).width()+"px'><div>"+data["workUnitCode"]+"</div><input type='hidden' name='capacity["+capacityCount+"].workUnitCode' value='"+data["workUnitCode"]+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[1]).width()+"px'><div>"+data["workUnitText"]+"</div></td>";
        tr += "<td style='width:"+$(gridTheadTh[2]).width()+"px'><div>"+data["standardCapacity"]+"</div><input type='hidden' name='capacity["+capacityCount+"].standardCapacity' value='"+data["standardCapacity"]+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[3]).width()+"px'><div>"+data["standardHours"]+"</div><input type='hidden' name='capacity["+capacityCount+"].standardHours' value='"+data["standardHours"]+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[4]).width()+"px'><a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='_delProcessCapacity(\""+data.workUnitCode+"\");'><@label key='delete.B'>删除</@label></a></td>";
        tr += "</tr>";
        $("tr#"+data.workUnitCode,  $currentDialog).remove();
        $("#processCapacityTable .gridTbody",  $currentDialog).find("table tbody").append(tr);
        capacityCount ++;
    }
    
    function _addProcessComponent(data) {
        if(!data)
            return;
        var gridTheadTh = $("#processComponentTable", $currentDialog).find("table thead th");
        var tr = "<tr id="+data["componentCode"]+">";
        tr += "<td style='width:"+$(gridTheadTh[0]).width()+"px'><div>"+data["componentCode"]+"</div><input type='hidden' name='component["+componentCount+"].componentCode' value='"+data["componentCode"]+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[1]).width()+"px'><div>"+data["componentText"]+"</div></td>";
        tr += "<td style='width:"+$(gridTheadTh[2]).width()+"px'><div>"+data["quantity"]+"</div><input type='hidden' name='component["+componentCount+"].quantity' value='"+data["quantity"]+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[3]).width()+"px'><a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='_delProcessComponent(\""+data.componentCode+"\");'><@label key='delete.B'>删除</@label></a></td>";
        tr += "</tr>";
        $("tr#"+data.componentCode,  $currentDialog).remove();
        $("#processComponentTable .gridTbody",  $currentDialog).find("table tbody").append(tr);
        componentCount ++;
    }
    
    function _addInspectPicture(data) {
        if(!data )
            return;
        inspectPictureCount++;
        var gridTheadTh = $("#processInspectPicTable", $currentDialog).find("table thead th");
        var _id = "inspectPicture_"+inspectPictureCount;
        
        var tr = "<tr id="+_id+">";
        tr += "<td style='width:"+$(gridTheadTh[0]).width()+"px'><div>"+data.fileName+"</div><input type='hidden' name='picture["+inspectPictureCount+"].fileName' value='"+data.fileName+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[1]).width()+"px'><div>"+Math.round(data.fileSize/1024)+"kb</div><input type='hidden' name='picture["+inspectPictureCount+"].attachmentCode' value='"+data.attachmentCode+"'/></td>";
        tr += "<td style='width:"+$(gridTheadTh[2]).width()+"px'><a title='<@label key='delete.B'>删除</@label>' target='ajax' class='btnDel' onclick='_delProcessAttachment(\""+_id+"\");'><@label key='delete.B'>删除</@label></a>";
        tr += "<a title='<@label key='download.B'>下载</@label>' target='dwzExport' class='btnAttach' href='${rc.getContextPath()}/manage/common/downloadAttachement?attachmentCode="+data.attachmentCode+"&fileName="+data.fileName+"'></a></td>"
        tr += "</tr>";
        $("#processInspectPicTable .gridTbody", $currentDialog).find("table tbody").append(tr);
        
    }
    
    function _delProcessAttachment(_id) {
        if(_id && _id!="")
            $("tr#"+_id, $currentDialog).remove();
    }
    
    function _delProcessComponent(code) {
        if(code){
            $("tr#"+code, $currentDialog).remove();
        }
    }
    function _delProcessCapacity(code) {
        if(code){
            $("tr#"+code, $currentDialog).remove();
        }
    }
    
    function saveProcessOperation(form) {
        var $form = $(form);

        if (!$form.valid()) {
            return false;
        }
        $('#import_fileupload', $.pdialog.getCurrent()).uploadify('upload', '*');
        
    }
    
    $(function(){
        <#if processOperation?? && processOperation.operationTypeEcode=="QUALITY"
                && processOperation.graphcollectFlag == 0>
            setTimeout(function(){
                $("div#uploadProcessInspectPicture", $currentDialog).hide();
            }, 0);
        </#if>
        $("input[name='graphcollectFlag']", $currentDialog).click(function(){
            if($(this).attr("checked")){
                $("div#uploadProcessInspectPicture", $currentDialog).show();
            }else{
                alertMsg.confirm("<@label key='graphicsUploadFile.M'>附件上传只对图形采集有效！</@label>", {
                    okCall: function(){
                        $("div#uploadProcessInspectPicture", $currentDialog).hide();
                    },
                    cancelCall: function(){
                        $("input[name='graphcollectFlag']", $currentDialog).attr("checked",true);
                    }
                });
            }
        });
    })
</script>
<script type="text/javascript" src="${rc.getContextPath()}/manage/js/businessJs/my_webuploader.js"></script>
<form method="post" action="${rc.getContextPath()}/manage/process/saveProcessOperation" class="pageForm required-validate" onsubmit="return validateCallback(this, popDialogAjaxDone)">
    <input type="hidden" name="id" value="<#if processOperation??>${processOperation.id!''}</#if>"/>
    <input type="hidden" name="processCode" value="<#if processOperation??>${processOperation.processCode!''}</#if>"/>
    <input type="hidden" name="processRev" value="<#if processOperation??>${processOperation.processRev!''}</#if>"/>
    <div class="pageContent">
    <div class="pageFormContent customFildset">
        <fieldset>
        <dl>
            <dt><@label key="operation.C,serialNumber.C,colon">工序序号：</@label></dt>
            <dd><input type="text" name="operationOrdinal" maxlength="20" class="required digits" value="<#if processOperation??>${processOperation.operationOrdinal!''}</#if>"/></dd></dl>
        <dl>
            <dt><@label key="operation.C,colon">工序：</@label></dt>
            <dd>
                <input id="operationOrdinalLookup.operationCode" name="operationCode" value="<#if processOperation??>${processOperation.operationCode!''}</#if>" type="hidden"/>
                <input class="required" id="operationOrdinalLookup.operationText" readonly="readonly" name="operationText" type="text" value="<#if processOperation??>${processOperation.operationText!''}</#if>" postField="operationText" />
            </dd>
        </dl>
        <dl>
        	<dt><@label key="standardCapacity.C">标准产能</@label></dt>
        	<dd>
            	<input  name="standardCapacity" size="22" type="text" maxlength="60" value="<#if processOperation??>${processOperation.standardCapacity!''}</#if>"/>
        	</dd>
        </dl>
        <dl class="notnormal">
            <dt><@label key="standardHours.C">标准用时</@label></dt>
            <dd>
                <input name="standardHours" size="22" type="text" maxlength="60" value="<#if processOperation??>${processOperation.standardHours!''}</#if>"/>
            </dd>
        </dl>
        <dl>
            <dt><@label key="operationType.C,colon">工序类型：</@label></dt>
            <dd><input type="text"  maxlength="20" readonly="readonly" value="<#if processOperation??>${processOperation.operationTypeText!''}</#if>"/></dd></dl>
        <dl>
            <dt><@label key="workUnitType.C,colon">作业单元类型：</@label></dt>
            <dd>
            <input id="workUnitTypeLookup.workUnitTypeCode" name="workUnitTypeCode" value="<#if processOperation??>${processOperation.workUnitTypeCode!''}</#if>" type="hidden"/>
            <input class="look" id="workUnitTypeLookup.typeText" name="typeText" type="text" postField="workUnitTypeCode" suggestFields="workUnitTypeCode,typeText" value="<#if processOperation??>${processOperation.typeText!''}</#if>" 
                suggestUrl="${rc.getContextPath()}/manage/workUnit/workUnitTypeSuggest" lookupGroup="workUnitTypeLookup"/>
            <a class="btnLook" href="${rc.getContextPath()}/manage/workUnit/selectWorkUnitType?lookupType=radio" rel="workUnitType_dialog" title="<@label key='select.C,workUnitType.C'>选择作业单元类型</@label>" lookupGroup="workUnitTypeLookup" ></a>
            </dd>
        </dl>
        <dl>
            <dt><@label key="confirmPoint.C,colon">确认点：</@label></dt>
            <dd><input type="checkbox" name="confirmFlag" <#if processOperation?? && processOperation.confirmFlag==1> checked</#if> value="1"/></dd>
        </dl>
        <dl  class="nowrap">
            <dt><@label key='description.C,colon'>备注：</@label></dt>
            <dd><textarea name="memo" rows="3" cols="40"><#if processOperation??>${processOperation.memo!''}</#if></textarea></dd>
        </dl>    
        </fieldset>
    </div>
    <div class="tabs">
    <div class="tabsHeader">
        <div class="tabsHeaderContent">
            <ul>
                <li id="attachment" data-selectedid="processOperation_attachment" class="exerInputS"><a href="javascript:;" id="select1"><span><@label key='attachment.C'>工艺附件</@label></span></a></li>
                <li id="Capacity" data-selectedid="processOperation_Capacity" class="exerInputS"><a href="javascript:;" id="select4"><span><@label key='cmprocessCapacity.C'>工艺产能</@label></span></a></li>
                <#if processOperation?? && processOperation.operationTypeEcode=="PRODUCTION">
                <li id="component" data-selectedid="processOperation_component" class="exerInputS"><a href="javascript:;" id="select2"><span><@label key='component.C'>组件</@label></span></a></li>
                <#else>
                <li id="quality" data-selectedid="processOperation_quality" class="exerInputS"><a href="javascript:;" id="select3"><span><@label key='qualityOperation.C'>质量工序设置</@label></span></a></li>
                </#if>
            </ul>
        </div>
    </div>
    <div class="tabsContent" style="border-bottom: 1px #d8dfe5 solid;height:280px">
        <div>
            <div class="pageHeader">
                <div id="uploader" class="wu-example">
                    <!--用来存放文件信息-->
                    <div id="processlist" class="uploader-list"></div>
                </div>
                <div id="processFile" class="choose-file" uploaderOption="{
                                    server:'${rc.getContextPath()}/manage/process/saveProcessAttachment',
                                    fileVal:'processfile',
                                    fileBnt: 'processFileBnt',
                                    fileList: 'processlist',
                                    beforeFileQueuedMsg: '<@label key='exeBat_type_msg.D'>请不要上传exe，bat，sh等可执行的文件</@label>',
                                    uploadSuccess: _addProcessAttachment
                                }"><@label key='chooseFile.C'>选择文件</@label></div>
                <div class="buttonActive" style="float: right;">
                    <div class="buttonContent"><button id="processFileBnt" type="button"><@label key='upload.B'>上传</@label></button></div>
                </div>
            </div>
            <table class="table canopration border" style="width: 100%;" id="processAttachMentTable">
                <thead>
                    <tr>
                        <th width="100px"><@label key='fileName.C'>文件名称</@label></th>
                        <th width="100px"><@label key='fileSize.C'>文件大小(bytes)</@label></th>
                        <th width="100px"><@label key='version.C'>版本</@label></th>
                        <th width="50px"><@label key="opera.C">操作</@label></th>
                    </tr>
                </thead>
                <tbody>
                    <#if processOperation?? && processOperation.attachment??>
                        <#list processOperation.attachment as attachment>
                            <tr id="processAttachment_${attachment.id!''}">
                                <td>${attachment.fileName!''}<input type="hidden" name="attachment[${attachment_index}].fileName" value="${attachment.fileName!''}"/></td>
                                <td>${(attachment.fileSize/1024)?int} kb<input type="hidden" name="attachment[${attachment_index}].attachmentCode" value="${attachment.attachmentCode!''}"/></td>    
                                <td><input type="text" class="textInput required" name="attachment[${attachment_index}].version" value="${attachment.version!''}"/></td>    
                                <td>
                                    <a title="<@label key='delete.B'>删除</@label>" target="ajax" class="btnDel" onclick="_delProcessAttachment('processAttachment_${attachment.id!''}');"><@label key="delete.B">删除</@label></a>
                                    <a title="<@label key='download.B'>下载</@label>" target="dwzExport" class="btnAttach" href="${rc.getContextPath()}/manage/common/downloadAttachement?attachmentCode=${attachment.attachmentCode!''}&fileName=${attachment.fileName!''}"></a>
                                </td>
                            </tr>
                        </#list>
                    </#if>
                </tbody>
            </table>
        </div>
        <div>
            <div class="panelBar">
                <ul class="toolBar">
                    <li><a class="add " target="dialog" mask="true" width="450" height="280" rel="addProcessCapacity" title="<@label key='addWorkUnit.D'>新增作业单元</@label>"
                    href="${rc.getContextPath()}/manage/process/addProcessCapacity"><span><@label key="add.B">新增</@label></span></a></li>
                </ul>
            </div>
            <table id="processCapacityTable" class="table canopration" style="width: 100%;" layoutH="320">
                <thead>
                    <tr>
                        <th width="70px"><@label key="workUnitCode.C">作业单元编号</@label></th>
                        <th width="70px"><@label key="workUnitText.C">作业单元名称</@label></th>
                        <th width="50px"><@label key="standardCapacity.C">标准产能</@label></th>
                         <th width="50px"><@label key="standardHours.C">标准用时</@label></th>
                        <th width="50px"><@label key="opera.C">操作</@label></th>
                    </tr>
                </thead>
                <tbody>
                	<#if processOperation?? && processOperation.capacity??>
                        <#list processOperation.capacity as capacity>
                            <tr id="${capacity.workUnitCode!''}">
                                <td>${capacity.workUnitCode!''} <input type="hidden" name="capacity[${capacity_index}].workUnitCode" value="${capacity.workUnitCode!''}"/></td>
                                <td>${capacity.workUnitText!''}</td>
                                <td>${capacity.standardCapacity!''} <input type="hidden" name="capacity[${capacity_index}].standardCapacity" value="${capacity.standardCapacity!''}"/></td>    
                                <td>${capacity.standardHours!''} <input type="hidden" name="capacity[${capacity_index}].standardHours" value="${capacity.standardHours!''}"/></td>    
                                <td>
                                    <a title="<@label key='delete.B'>删除</@label>" target="ajax" class="btnDel" onclick="_delProcessCapacity('${capacity.workUnitCode!''}');"><@label key="delete.B">删除</@label></a>
                                </td>
                            </tr>
                        </#list>
                    </#if>
                </tbody>
            </table>
        </div>
        <div>
            <#if processOperation?? && processOperation.operationTypeEcode=="PRODUCTION">
            <div class="panelBar">
                <ul class="toolBar">
                    <li><a class="add " target="dialog" mask="true" width="450" height="280" rel="addProcessComponent" title="<@label key='add.B,component.C'>新增组件</@label>"
                    href="${rc.getContextPath()}/manage/process/addProcessComponent"><span><@label key="add.B">新增</@label></span></a></li>
                </ul>
            </div>
            <table id="processComponentTable" class="table canopration" style="width: 100%;" layoutH="340">
                <thead>
                    <tr>
                        <th width="50px"><@label key="component.C,code.C">组件编号</@label></th>
                        <th width="100px"><@label key="component.C,name.C">组件名称</@label></th>
                        <th width="30px"><@label key="quantity.C">数量</@label></th>
                        <th width="50px"><@label key="opera.C">操作</@label></th>
                    </tr>
                </thead>
                <tbody>
                    <#if processOperation?? && processOperation.component??>
                        <#list processOperation.component as component>
                            <tr id="${component.componentCode!''}">
                                <td>${component.componentCode!''} <input type="hidden" name="component[${component_index}].componentCode" value="${component.componentCode!''}"/></td>
                                <td>${component.componentText!''}</td>
                                <td>${component.quantity!''} <input type="hidden" name="component[${component_index}].quantity" value="${component.quantity!''}"/></td>    
                                <td>
                                    <a title="<@label key='delete.B'>删除</@label>" target="ajax" class="btnDel" onclick="_delProcessComponent('${component.componentCode!''}');"><@label key="delete.B">删除</@label></a>
                                </td>
                            </tr>
                        </#list>
                    </#if>
                </tbody>
            </table>
            <#else>
            <div class="pageHeader">
                <fieldset class="pageFormContent">
                    <dl>
                        <dt>选择采集方式</dt>
                        <dd>
                            <input type="checkbox" name="textcollectFlag" value="1" <#if processOperation?? && processOperation.textcollectFlag==1>checked</#if>/>文本
                            <input type="checkbox" name="graphcollectFlag" value="1" <#if processOperation?? && processOperation.graphcollectFlag==1>checked</#if>/>图形
                        </dd>
                    </dl>
                    <dl>
                        <dt>默认采集类型</dt>
                        <dd>
                            <select name="collectModeEcode" >
                                <#if defectcollectMode??>
                                    <#list defectcollectMode as ecode>
                                        <option value="${ecode.eCode!''}"
                                         <#if processOperation?? && processOperation.collectModeEcode==ecode.eCode>selected</#if>>${ecode.eCodeText!''}</option>
                                    </#list>
                                </#if>
                            </select>
                        </dd>
                    </dl>
                </fieldset>
                <div id="uploadProcessInspectPicture">
                    <div id="uploader" class="wu-example">
                        <!--用来存放文件信息-->
                        <div id="processPictureList" class="uploader-list"></div>
                    </div>
                    <div id="processPictureFile" class="choose-file" uploaderOption="{
                                    server:'${rc.getContextPath()}/manage/process/saveProcessinspectpicture',
                                    fileVal:'processPicture',
                                    fileBnt: 'processPictureBnt',
                                    fileList: 'processPictureList',
                                    beforeFileQueuedMsg: '<@label key='exeBat_type_msg.D'>请不要上传exe，bat，sh等可执行的文件</@label>',
                                    uploadSuccess: _addInspectPicture

                                }"><@label key='chooseFile.C'>选择文件</@label></div>
                    <div class="buttonActive" style="float: right;">
                        <div class="buttonContent"><button id="processPictureBnt" type="button"><@label key='upload.B'>上传</@label></button></div>
                    </div>
                </div>
            </div>
            <table class="table canopration" style="width: 100%;" id="processInspectPicTable">
                <thead>
                    <tr>
                        <th width="100px"><@label key='fileName.C'>文件名称</@label></th>
                        <th width="100px"><@label key='fileSize.C'>文件大小(bytes)</@label></th>
                        <th width="50px"><@label key="opera.C">操作</@label></th>
                    </tr>
                </thead>
                <tbody>
                    <#if processOperation?? && processOperation.picture??>
                        <#list processOperation.picture as picture>
                            <tr id="inspectPicture_${picture.id!''}">
                                <td>${picture.fileName!''} <input type="hidden" name="picture[${picture_index}].fileName" value="${picture.fileName!''}"/></td>
                                <td>${(picture.fileSize/1024)?int} kb <input type="hidden" name="picture[${picture_index}].attachmentCode" value="${picture.attachmentCode!''}"/></td>
                                <td>
                                    <a title="<@label key='delete.B'>删除</@label>" target="ajax" class="btnDel" onclick="_delProcessAttachment('inspectPicture_${attachment.id!''}');"><@label key="delete.B">删除</@label></a>
                                    <a title="<@label key='download.B'>下载</@label>" target="dwzExport" class="btnAttach" href="${rc.getContextPath()}/manage/common/downloadAttachement?attachmentCode=${attachment.attachmentCode!''}&fileName=${attachment.fileName!''}"></a>
                                </td>
                            </tr>
                        </#list>
                    </#if>
                </tbody>
            </table>
            </#if>
        </div>
    </div>
    </div>
    <div class="formBar">
        <ul>
            <li><div class="buttonActive"><div class="buttonContent"><button type="submit"><@label key="save.B">保存</@label></button></div></div></li>
            <li>
                <div class="buttonActiveGrey"><div class="buttonContent"><button type="button" class="close"><@label key="cancel.B">取消</@label></button></div></div>
            </li>
        </ul>
    </div>
    </div>
</form>

